/**
 * Copyright 2010 Balaji Thennarangam.
 */
package com.kathez.studentportal.entity;

public abstract class AbstractPrimaryKey implements PrimaryKey{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 3425946747247797082L;
	private StringBuffer keyString = new StringBuffer();	
	private static final String DE_LIMITER = "@";

	public AbstractPrimaryKey() {
		super();
	}

	@Override
	public Object[] getKeys() {
		return this.setKeys();
	}

	@Override
	public String getKeysAsString() {
		return this.setKeysAsString(setKeys()).toString();
	}
	
	protected abstract Object[] setKeys();
	
	private StringBuffer setKeysAsString(Object[] keys){
		this.keyString.delete(0, this.keyString.length());
		if(keys != null && keys.length > 0){
			int len = keys.length;
			for(int i = 0; i < len; i++){
				if(keys[i] != null){
					this.keyString.append(keys[i]);
					if((len-1) > i)
						this.keyString.append(DE_LIMITER);
				}
			}
		}
		return this.keyString;
	}

}